package com.shanjupay.merchant.controller;


import com.shanjupay.merchant.api.AppService;
import com.shanjupay.merchant.api.dto.AppDTO;
import com.shanjupay.merchant.common.util.SecurityUtil;
import com.shanjupay.transaction.api.PayChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(value = "商户平台-应用管理",tags = "商户平台-应用相关接口", description = "商户平台-应用相关")
public class AppController {

    @Reference
    private AppService appService ;










    @ApiOperation("根据appid获取应用的详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "appId",value = "商户应用id",required = true,dataType = "String",paramType = "path")
    })
    @GetMapping(value = "/my/apps/{appId}")
    public AppDTO getApp(@PathVariable(value = "appId",required = true) String appId){
        return appService.getAppById(appId) ;
    }




    @ApiOperation("查询商户下的应用列表")
    @GetMapping(value = "/my/apps")
    public List<AppDTO> queryMyApps(){
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.queryAppByMerchant(merchantId);
    }

    @ApiOperation("商户创建应用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "app",value = "应用信息",required = true ,dataType = "AppDTO", paramType = "body")
    })
    @PostMapping(value = "/my/apps")
    public AppDTO createApp(@RequestBody AppDTO app){

        Long merchantId = SecurityUtil.getMerchantId();

        return appService.createApp(merchantId,app);
    }










}
